package com.hey.controller;

import com.hey.entity.User;
import com.hey.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON_VALUE;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping(value = "user",produces = "application/json")
    public Mono<User> save(@RequestBody User user){
        return userService.save(user);
    }

    @DeleteMapping("/{username}")
    public Mono<Long> deleteByUsername(@PathVariable String username) {
        return userService.deleteByUsername(username);
    }

    @GetMapping("/{username}")
    public Mono<User> findByUsername(@PathVariable String username) {
        return userService.findByUsername(username);
    }

    @GetMapping("")
    public Flux<User> findAll() {
        return userService.findAll();
    }

    @GetMapping(value = "all",produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
    public Flux<User> findAllByStream(){ return userService.findAll(); }
}
